home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 #1 / Ham Radio 2000.iso / ham2000 / tcp_ip / wnos / wn941101 / tcptimer.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-10  |  1.4 KB  |  66 lines

  1. /* TCP timeout routines */
  2. #include <stdio.h>
  3. #include "global.h"
  4. #include "mbuf.h"
  5. #include "timer.h"
  6. #include "netuser.h"
  7. #include "internet.h"
  8. #include "tcp.h"
  9.  
  10. int Tcp_retry = 5;
  11.  
  12. /* Timer timeout */
  13. void
  14. tcp_timeout(void *p)
  15. {
  16.     struct tcb *tcb = p;
  17.  
  18.     if(p == NULLTCB)
  19.         return;
  20.  
  21.     /* Make sure the timer has stopped (we might have been kicked) */
  22.     stop_timer(&tcb->timer);
  23.  
  24.     switch(tcb->state){
  25.     case TCP_TIME_WAIT:                /* 2MSL timer has expired */
  26.         close_self(tcb,NORMAL);
  27.         break;
  28.     default:
  29.         /* Retransmission timer has expired */
  30.         tcb->flags.retran = 1;    /* Indicate > 1  transmission */
  31.         tcb->backoff++;
  32.         if(Tcp_retry > 0)
  33.             if((tcb->backoff > Tcp_retry && tcb->state != TCP_ESTABLISHED)
  34.               || (tcb->backoff > Tcp_retry * 5
  35.               && (tcb->state == TCP_ESTABLISHED || tcb->state == TCP_FINWAIT1))) {
  36.                 close_self(tcb,TIMEOUT);
  37.                 break;
  38.             }
  39.         tcb->snd.ptr = tcb->snd.una;
  40.         /* Reduce slowstart threshold to half current window */
  41.         tcb->ssthresh = tcb->cwind / 2;
  42.         tcb->ssthresh = max(tcb->ssthresh,tcb->mss);
  43.         /* Shrink congestion window to 1 packet */
  44.         tcb->cwind = tcb->mss;
  45.         tcp_output(tcb);
  46.     }
  47. }
  48.  
  49. #ifdef XXX
  50. /*
  51.  * compiler-conform function in tcpout.c - DB3FL.920124
  52.  * Backoff function - the subject of much research
  53.  *
  54.  */
  55. int32
  56. backoff(n)
  57. int n;
  58. {
  59.     int32 j = 1;
  60.  
  61.     if(n > 31)
  62.         n = 31;
  63.     return (j <<= n);            /* Binary exponential back off */
  64. }
  65. #endif /* XXX */
  66.